package com.tao.common

import android.app.Application
import android.content.res.Configuration
import androidx.multidex.MultiDexApplication
import com.alibaba.android.arouter.launcher.ARouter
import com.elvishew.xlog.LogConfiguration
import com.elvishew.xlog.LogLevel
import com.elvishew.xlog.XLog
import com.elvishew.xlog.interceptor.BlacklistTagsFilterInterceptor

abstract class BaseApp : MultiDexApplication(){
    override fun onCreate() {
        super.onCreate()
        setContext(this)
        val build = LogConfiguration.Builder()
            .logLevel(LogLevel.ALL)
            .tag("T800")
        if (!BuildConfig.DEBUG) {
            build.addInterceptor(
                BlacklistTagsFilterInterceptor(    // 添加黑名单 TAG 过滤器
                    "T800"
                )
            )
        }
        XLog.init(build.build())
        XLog.e(this)

        // 这两行必须写在init之前，否则这些配置在init过程中将无效
        if (BuildConfig.DEBUG) {
            // 打印日志
            ARouter.openLog();
            // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
            ARouter.openDebug();
        }
        // 尽可能早，推荐在Application中初始化
        ARouter.init(getContext());
    }

    override fun onLowMemory() {
        super.onLowMemory()
    }

    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
    }

    companion object {
        private lateinit var context: Application
        fun getContext(): Application {
            return context
        }

        fun setContext(context: Application) {
            this.context = context;
        }
    }
}